package com.bt.lms.ui.page.teaching.supervise;

import com.bt.lms.ui.page.sys.style.LabStyle;
import com.bt.lms.ui.page.sys.utils.MyHBox;
import com.bt.lms.ui.page.sys.utils.MyVBox;
import com.bt.lms.ui.page.teaching.supervise.action.PageAddRealTimeCancelBtnAction;
import com.bt.lms.ui.vo.PageSkipInfo;
import javafx.collections.ObservableList;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

/**
 * 新增实时课堂界面
 */
public class PageRealTimeClassAdd extends VBox {

    /**
     * 界面跳转数据
     */
    private final PageSkipInfo pageSkipInfo;

    /**
     * 构建界面
     * @param pageSkipInfo 界面跳转数据
     */
    public PageRealTimeClassAdd(PageSkipInfo pageSkipInfo) {
        //维护
        this.pageSkipInfo = pageSkipInfo;

        //大小
        int wight = 1280;
        this.setPrefWidth(wight);
        this.setPrefHeight(650);

        //布局
        Insets insets = new Insets(0);
        this.setPadding(insets);

        //组件
        //定位区域
        MyHBox locationHBox = new MyHBox();
        locationHBoxInit(locationHBox);
        this.getChildren().add(locationHBox);

        //输入区域
        MyVBox inputVBox = new MyVBox();
        inputVBoxInit(inputVBox);
        this.getChildren().add(inputVBox);

        //控制区域
        MyHBox controlHBox = new MyHBox();
        controlHBoxInit(controlHBox);
        this.getChildren().add(controlHBox);
    }

    /**
     * 输入区域初始化
     *
     * @param inputVBox 输入区域
     */
    private void inputVBoxInit(   MyVBox inputVBox) {

        //布局
        Insets insets = new Insets(12);
        inputVBox.setPadding(insets);
        inputVBox.setSpacing(8);
        inputVBox.setAlignment(Pos.CENTER_LEFT);

        //组件（位置）
        Label locationLab = new Label("新增实时课堂");
        //组件添加
        ObservableList<Node> locationChildren = inputVBox.getChildren();
        locationChildren.add(locationLab);

        //组件（输入网格
        GridPane gridPane = inputGrid();
        inputVBox.getChildren().add(gridPane);
    }

    /**
     * 网格布局
     * @return 网格布局
     */
    private    GridPane inputGrid() {

        //新建网格布局
        GridPane res = new GridPane();

        //大小
        res.setPrefWidth(1280);
        res.setPadding(new Insets(5));
        res.setHgap(10);//间隙（左右）
        res.setVgap(15);//间隙（上下）

        //主题 name
        Label nameLab = new Label("主题");
        GridPane.setHalignment(nameLab,HPos.RIGHT);
        DatePicker nameLabDP = new DatePicker();
        res.add(nameLab, 0, 1);
        res.add(nameLabDP, 1, 1);
        GridPane.setHalignment(nameLab, HPos.RIGHT);

        //主讲人/主讲教
        Label compereLab = new Label("主讲人/主讲教");
        GridPane.setHalignment(compereLab,HPos.RIGHT);
        res.add(compereLab,0,2);
        VBox compereVBox = new VBox();
        compereVBoxInit(compereVBox);
        res.add(compereVBox,1,2);

        //实时课堂日期
        Label dateLab = new Label("实时课堂日期");
        GridPane.setHalignment(dateLab,HPos.RIGHT);
        res.add(dateLab,0,3);
        DatePicker dateDP = new DatePicker();
        res.add(dateDP,1,3);

        //起止时间
        Label startStopLab = new Label("起止时间");
        GridPane.setHalignment(startStopLab,HPos.RIGHT);
        res.add(startStopLab,0,4);
        HBox startStopHBox = new MyHBox();
        startStopHBoxInit(startStopHBox);
        res.add(startStopHBox,1,4);

        //课程时长
        Label durationLab = new Label("课程时长");
        res.add(durationLab,0,5);
        GridPane.setHalignment(durationLab,HPos.RIGHT);
        HBox durationHBox = new MyHBox();
        durationHBoxInit(durationHBox);
        res.add(durationHBox,1,5);

        //课程资料 data
        Label dataLab = new Label("课程资料");
        GridPane.setHalignment(dataLab,HPos.RIGHT);
        res.add(dataLab,0,6);
        HBox dataHBox = new HBox();
        dataLabInit(dataHBox);
        res.add(dataHBox,1,6);


        return res;
    }

    /**
     * 控制区域初始化
     *
     * @param controlHBox 控制区域
     */
    private void controlHBoxInit(   MyHBox controlHBox) {

        //布局
        Insets insets = new Insets(10);
        controlHBox.setPadding(insets);
        controlHBox.setSpacing(10);
        controlHBox.setAlignment(Pos.CENTER);

        //组件(确认)
        Button saveBtn = new Button("确认");
        //大小控制
        Insets saveBtnInsets = new Insets(10, 20, 10, 20);
        saveBtn.setPadding(saveBtnInsets);
        //组件添加
        ObservableList<Node> saveBtnChildren = controlHBox.getChildren();
        saveBtnChildren.add(saveBtn);

        //组件(取消)
        Button cancelBtn = new Button("取消");
        //大小控制
        Insets cancelBtnInsets = new Insets(10, 20, 10, 20);
        cancelBtn.setPadding(cancelBtnInsets);
        //事件
        PageAddRealTimeCancelBtnAction pageAddRealTimeCancelBtnAction = new PageAddRealTimeCancelBtnAction(pageSkipInfo);
        cancelBtn.setOnAction(pageAddRealTimeCancelBtnAction);
        //组件添加
        ObservableList<Node> cancelBtnChildren = controlHBox.getChildren();
        cancelBtnChildren.add(cancelBtn);

    }


    /**
     * 定位区域初始化
     *
     * @param locationHBox 定位区域容器
     */
    private void locationHBoxInit(   MyHBox locationHBox) {

        //控制数据
        int height = 42;

        //大小
        locationHBox.setPrefHeight(height);

        //布局
        Insets insets = new Insets(5);
        locationHBox.setPadding(insets);
        locationHBox.setSpacing(0);
        locationHBox.setAlignment(Pos.CENTER_LEFT);

        //组件
        Label siteLab = new Label("当前位置：");
        Label oneCatalogLab = new Label("🏠>系统管理");
        Label twoCatalogLab = new Label(">实时课堂管理");
        Label threeCatalogLab = new Label(">新增实时课堂");

        //添加组件
        locationHBox.getChildren().addAll(siteLab, oneCatalogLab, twoCatalogLab, threeCatalogLab);

    }

    /**
     * 网格区域的主讲师初始化
     * @param compereVBox 主讲师盒子
     */
    private void compereVBoxInit(   VBox compereVBox) {

        compereVBox.setSpacing(5);

        CheckBox oneCheckBox = new CheckBox("董老师");
        compereVBox.getChildren().add(oneCheckBox);

        CheckBox twoCheckBox = new CheckBox("王老师");
        compereVBox.getChildren().add(twoCheckBox);

        CheckBox threeCheckBox = new CheckBox("毛老师");
        compereVBox.getChildren().add(threeCheckBox);

    }

    /**
     * 起止时间盒子初始化
     * @param startStopHBox 起止时间
     */
    private void startStopHBoxInit(   HBox startStopHBox) {

        //布局
        startStopHBox.setSpacing(5);

        DatePicker beginDP = new DatePicker();
        startStopHBox.getChildren().add(beginDP);

        Label linkLab = new Label("-");
        startStopHBox.getChildren().add(linkLab);

        DatePicker finishDP = new DatePicker();
        startStopHBox.getChildren().add(finishDP);

        Label hintLab = new Label("(比如：12:25-13:45)");
        LabStyle.notWeight(hintLab);
        startStopHBox.getChildren().add(hintLab);

    }

    /**
     * 课程时长盒子初始化
     * @param durationHBox 课程时长盒子
     */
    private void durationHBoxInit(   HBox durationHBox) {

        durationHBox.setSpacing(2);

        TextField textField = new TextField();
        durationHBox.getChildren().add(textField);

        Label label = new Label("分钟");
        durationHBox.getChildren().add(label);
    }

    /**
     * 课程资料盒子初始化
     * @param dataHBox 课程资料盒子
     */
    private void dataLabInit(   HBox dataHBox) {

        //布局
        dataHBox.setSpacing(2);

        HBox dataHBoxInfo = new HBox();
        dataHBoxInfoInit(dataHBoxInfo);
        dataHBox.getChildren().add(dataHBoxInfo);

        Button uploadingBtn = new Button("上传");
        dataHBox.getChildren().add(uploadingBtn);
    }

    /**
     * 课程资料信息盒子初始化
     * @param dataHBoxInfo 课程资料信息盒子
     */
    private void dataHBoxInfoInit(   HBox dataHBoxInfo) {

        //布局
        dataHBoxInfo.setSpacing(5);
        dataHBoxInfo.setPrefWidth(250);
        dataHBoxInfo.setAlignment(Pos.CENTER_LEFT);
        //组件
        Button selectBtn = new Button("选择文件");
        dataHBoxInfo.getChildren().add(selectBtn);
        Label stateLab = new Label("未选择文件");
        dataHBoxInfo.getChildren().add(stateLab);
    }
}
